package xyc.szk.web.servlet.cookie;
/*
 * @Description:
 * @Author: 山志凯
 * @Date: 2021-04-07
 * @Time: 09:16
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie01")
public class CookieServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建一个cookie
        Cookie cookie = new Cookie("username", "tom");
        resp.addCookie(cookie);//即服务器向浏览器发送一个响应头：Set-Cookie:username=tom
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
